import config from "config";

export const ncOptions = {
    method: 'POST',
    json: true,
    qs: {
        format: 'json'
    },
    headers: {"OCS-APIREQUEST": true}
}

export const getBase64Auth = (user, passwd) => {
    return "Basic " + new Buffer(user + ":" + passwd).toString("base64")
}

export const cleanUrl = (url)=>{
    return url.replace(/([^:]\/)\/+/g, "$1")
}

const GraphExtensionList = config.get('allowedGraphExtensions');

export const getExtensionList = (param)=>{
    return param?param.split(',').map((ext)=>'.'+ext):GraphExtensionList
}

export const parseFilePath = function(path){
    let dot = path.lastIndexOf('.'),start = path.lastIndexOf('/')>0?path.lastIndexOf('/')+1:0,
        format,filename,fullname;
    if(dot>0){
        format = path.substring(dot + 1)
        filename = path.substring(start,dot)
    }else{
        format = 'xml'
        filename = path.substring(start)
    }
    fullname = filename + '.' + format
    return {filename,format,fullname}
}